public class Solution {
    public static void main(String[] args) {
        int[] arr = new int[]{3,3};
        removeElement(arr,3);
    }
    //移除数组
    public static int removeElement(int[] nums, int val) {
        int i = 0;
        int j = nums.length-1;
        int count = j+1;

        while(i < j) {
            while(j > i && nums[j] == val) {
                j--;
                count--;
            }
            while(i < j && nums[i] == val) {
                nums[i] = nums[j];
                j--;
                count--;
            }
            if(nums[i] != val) {
                i++;
            }
        }
        if(i == j && nums[i] == val) {
            return count-1;
        }
        return count;
    }
}
